import '../model/paging_model.dart';
import '../utils/date_utils.dart';
import 'result_model.dart';

///考试:查询:请求
class TestBatchExamQueryReq extends PagingQueryReq {
  final String batchId, name;
  final int subjectVal, status;

  TestBatchExamQueryReq({
    required this.batchId,
    required this.name,
    required this.subjectVal,
    required this.status,
    super.index,
    super.size,
  });

  @override
  Map<String, dynamic> toMap() {
    final map = super.toMap();
    map['subjectVal'] = subjectVal;
    map['name'] = name;
    map['status'] = status;
    return map;
  }
}

///考试:查询:响应
class TestBatchExamQueryRes extends PagingQueryRes<TestBatchExamItemRes> {
  TestBatchExamQueryRes({
    required super.retCode,
    required super.retMessage,
    super.total,
    super.rows,
  });

  factory TestBatchExamQueryRes.fromModel(final ResultModelRes res) {
    final ret = PagingQueryRes.fromModel(
      res,
      (row) => TestBatchExamItemRes.fromMap(row),
    );
    return TestBatchExamQueryRes(
      retCode: ret.retCode,
      retMessage: ret.retMessage,
      total: ret.total,
      rows: ret.rows,
    );
  }
}

///考试:数据项:响应
class TestBatchExamItemRes {
  final String id, name, remark;
  final int subjectVal, fullScore, status;
  final double discount;
  final DateTime? createdAt;

  const TestBatchExamItemRes({
    required this.id,
    required this.name,
    required this.remark,
    required this.subjectVal,
    required this.fullScore,
    required this.status,
    required this.discount,
    required this.createdAt,
  });

  factory TestBatchExamItemRes.fromMap(final Map<String, dynamic> map) =>
      TestBatchExamItemRes(
        id: map['id'] ?? '',
        name: map['name'] ?? '',
        remark: map['remark'] ?? '',
        subjectVal: map['subjectVal'] ?? 0,
        fullScore: map['fullScore'] ?? 0,
        discount: map['discount'] ?? 0.0,
        status: map['status'] ?? 0,
        createdAt: dateUtils.parse('yyyy-MM-dd HH:mm:ss', map['createdAt']),
      );
}

///考试:加载:响应
class TestBatchExamInfoRes extends TestBatchExamItemRes with ModelRes {
  @override
  final int retCode;
  @override
  final String retMessage;

  TestBatchExamInfoRes({
    required this.retCode,
    required this.retMessage,
    required TestBatchExamItemRes item,
  }) : super(
          id: item.id,
          name: item.name,
          remark: item.remark,
          subjectVal: item.subjectVal,
          fullScore: item.fullScore,
          status: item.status,
          discount: item.discount,
          createdAt: item.createdAt,
        );

  factory TestBatchExamInfoRes.fromModel(final ResultModelRes res) =>
      TestBatchExamInfoRes(
        retCode: res.retCode,
        retMessage: res.retMessage,
        item: TestBatchExamItemRes.fromMap(res.toMap),
      );
}

///考试:新增:请求
class TestBatchExamAddReq {
  final String batchId, name, remark;
  final int subjectVal, fullScore;
  final double discount;

  const TestBatchExamAddReq({
    required this.batchId,
    required this.name,
    required this.subjectVal,
    required this.fullScore,
    required this.discount,
    required this.remark,
  });

  Map<String, dynamic> toMap() => {
        'name': name,
        'remark': remark,
        'subjectVal': subjectVal,
        'fullScore': fullScore,
        'discount': discount,
      };
}

///考试:修改:请求
class TestBatchExamModifyReq {
  final String id, name, remark;
  final int subjectVal, fullScore, status;
  final double discount;

  const TestBatchExamModifyReq({
    required this.id,
    required this.name,
    required this.remark,
    required this.subjectVal,
    required this.fullScore,
    required this.discount,
    required this.status,
  });

  Map<String, dynamic> toMap() => {
        'name': name,
        'remark': remark,
        'subjectVal': subjectVal,
        'fullScore': fullScore,
        'discount': discount,
        'status': status,
      };
}
